package com.ymatou.iapi.trading.operate.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.ChangeDeliveryInfoReq;
import com.ymatou.iapi.trading.operate.service.ChangeDeliveryInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 更新发货信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ChangeDeliveryInfo {

	private static ChangeDeliveryInfoReq codnbean;
	private static ChangeDeliveryInfoCall codncall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新发货信息");
	}

	@Before
	public void caseUp() {

		codnbean = new ChangeDeliveryInfoReq();
		codncall = new ChangeDeliveryInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(codncall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ChangeDeliveryInfo_001() {
		Logger.start(true, "更新发货信息");
		try {
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			String originalBillCode = placeOrderResp.getOrderList().get(0)
					.getBillCode();

			Logger.comment("前置数据准备结束");

			String newBillCode = TestDataManager.randomStr(10);

			codnbean.setOrderId(orderId);
			codnbean.setSellerId(sellerId);
			codnbean.setOriginalBillCode(originalBillCode);
			codnbean.setNewBillCode(newBillCode);
			codnbean.setLogisticsCompany("autotest 拼邮");

			// 发送请求
			codncall.setData(codnbean);
			codncall.callService();

			Logger.verifyEquals(ECode.SUCCESS, codncall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ChangeDeliveryInfo_002() {
		Logger.start(true, "原始物流单号不存在");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			String billCode = placeOrderResp.getOrderList().get(0)
					.getBillCode();

			String originalBillCode = "abc";

			Logger.comment("前置数据准备结束");

			String newBillCode = TestDataManager.randomStr(10);

			codnbean.setOrderId(orderId);
			codnbean.setSellerId(sellerId);
			codnbean.setOriginalBillCode(originalBillCode);
			codnbean.setNewBillCode(newBillCode);
			codnbean.setLogisticsCompany("autotest 拼邮");

			// 发送请求
			codncall.setData(codnbean);
			codncall.callService();
			Logger.verifyEquals(ECode.SUCCESS, codncall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ChangeDeliveryInfo_003() {
		Logger.start(true, "订单号不存在");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			String billCode = placeOrderResp.getOrderList().get(0)
					.getBillCode();

			Logger.comment("前置数据准备结束");

			String newBillCode = TestDataManager.randomStr(10);

			codnbean.setOrderId(1111);
			codnbean.setSellerId(sellerId);
			codnbean.setOriginalBillCode(billCode);
			codnbean.setNewBillCode(newBillCode);
			codnbean.setLogisticsCompany("autotest 拼邮");

			// 发送请求
			codncall.setData(codnbean);
			codncall.callService();
			Logger.verifyEquals("200", codncall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ChangeDeliveryInfo_004() {
		Logger.start(true, "订单号不属于当前用户");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = PlaceOrderService.dispatchedOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			String billCode = placeOrderResp.getOrderList().get(0)
					.getBillCode();

			Logger.comment("前置数据准备结束");

			String newBillCode = TestDataManager.randomStr(10);

			codnbean.setOrderId(orderId);
			codnbean.setSellerId(1111);
			codnbean.setOriginalBillCode(billCode);
			codnbean.setNewBillCode(newBillCode);
			codnbean.setLogisticsCompany("autotest 拼邮");

			// 发送请求
			codncall.setData(codnbean);
			codncall.callService();
			Logger.verifyEquals("200", codncall.getCode(), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}